package com.gw.crm.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.io.*;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class TxtReadUtil {
    public static void main(String[] args) {

//        JSONObject bookObj = new JSONObject();
//        bookObj.put("filePath","D:/Other/temp/2024/05/06/srtxxd.txt");
//        bookObj.put("defaultLine",1500);
//        bookObj.put("Charset","GBK");

        JSONObject bookObj = new JSONObject();
        bookObj.put("filePath","D:/Other/temp/2024/05/06/daokuiyixian.txt");
        bookObj.put("defaultLine",27469);
        bookObj.put("Charset","GBK");

        int defaultLine = bookObj.getIntValue("defaultLine");
        String filePath = bookObj.getString("filePath");

        Scanner scanner = new Scanner(System.in);

        try {
            // springboot3.0版本
//            BufferedReader br = new BufferedReader(new FileReader(file, Charset.forName(bookObj.getString("Charset"))));
            FileInputStream fis = new FileInputStream(filePath);
            InputStreamReader isr = new InputStreamReader(fis,bookObj.getString("Charset"));
            BufferedReader br = new BufferedReader(isr);
            String content = "";
            List<String> contentList = new ArrayList<>();
            int line = 0;

            while(content != null) {
                content = br.readLine();
                contentList.add(content);
                line++;
            }

            System.out.println("共计 "+line+" 行内容");

            System.out.println("当前行："+defaultLine);

            System.out.println("请输入行号或操作指令:");

            while(scanner.hasNext()){
                String next = scanner.next();
                StringBuffer sb0 = new StringBuffer();
                DateFormat df0 = new SimpleDateFormat();
                sb0.append(df0.format(new Date()));
                sb0.append(" [http-nio-9208-exec-9] DEBUG c.c.c.m.Q.selectQualityCheckCoalSeamListBySamplingDate");
                System.out.println(sb0);
                sb0.append("- ==>  Preparing: select id, mine_name, face_number, coal_seams_num, sampling_number, sampling_date, stop_distance, tunnel_type, remarks, create_id, create_time, update_id, update_time");
                System.out.println(sb0);
                System.out.println(sb0);
                System.out.println(sb0);
                System.out.println(sb0);
                System.out.println(sb0);
                if(next.equalsIgnoreCase("q")){
                    System.out.println("退出");
                    break;
                }else if(next.equalsIgnoreCase("s")){
                    defaultLine++;
                    System.out.println("第"+defaultLine+"行内容: "+contentList.get(defaultLine));
                }else if(next.equalsIgnoreCase("w")){
                    defaultLine--;
                    System.out.println("第"+defaultLine+"行内容: "+contentList.get(defaultLine));
                }else {
                    defaultLine = Integer.valueOf(next);
                    System.out.println("第"+defaultLine+"行内容: "+contentList.get(defaultLine));
                }
            }

        }catch (Exception e){
            e.printStackTrace();
        }


        scanner.close();
    }

}
